<?php

/**
 * Utilities for strings
 *
 * @package Rapide_Util
 */
class Rapide_Util_String {

	/**
	* Removes characters from input string

	* @param string $sString
	* @param string $sCharacters
	* @return string output string without characters 
	*/
	public function removeCharacters($sString, $sCharacters) {
		$iStringLen = strlen($sString);
		
		if($iStringLen<1)
			return;
		
		$sStringOut = '';
		for($i = 0; $i < $iStringLen; $i++) {
			$sCurrentChar = substr($sString, $i, 1);
		
			if(strpos($sCharacters, $sCurrentChar) === false)
				$sStringOut .= $sCurrentChar;
		}
	 
		return $sStringOut;
	}

	/**
	 * Includes string behind particular char string input
	 * 
	 * Useful for formatting some data, for example telephone numbers .
	 *
	 * @param string $sString
	 * @param array $aBreakStrings array of break strings (char_position => what_string_include_behind_char)
	 * @return string
	 */
	public function formatString($sStringIn, array $aBreakStrings) {
		if(strlen($sStringIn) < max(array_keys($aBreakStrings)))
			return;

		$iStart = 0;
		
		$sStringOut = '';
		foreach($aBreakStrings as $iPosition => $sString) {
			$sStringOut .= substr($sStringIn, $iStart, $iPosition-$iStart);
			$sStringOut .= $sString;
			$iStart = $iPosition;
		}

		$sStringOut .= substr($sStringIn, $iStart, strlen($sStringIn));

		return $sStringOut;
	}
}

?>